<template>
  <el-button size="mini">
    <el-dropdown :hide-on-click="false" trigger="click">
      <span class="el-dropdown-link">
        <div class="but_text jsb">
          <i class="iconfont icon-02xitongguanli-peizhixinxi-gongnengdaohang-2"></i>
          <span class="f12">列表展示列控制 </span>
          <i class="el-icon-caret-bottom"></i>
        </div>
      </span>
      <el-dropdown-menu slot="dropdown">
        <div class="check_max">
          <el-checkbox-group v-model="checkList" @change="rowCheckChange" class="fdc">
            <el-checkbox v-for="(item, index) in rowKeyCopy" :key="index" :label="item.key">{{
              item.label
            }}</el-checkbox>
          </el-checkbox-group>
        </div>
      </el-dropdown-menu>
    </el-dropdown>
  </el-button>
</template>

<script>
export default {
  name: 'RowSet',
  props: {
    rowKey: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      rowKeyCopy: [],
      checkList: []
    }
  },
  created() {
    this.rowKeyCopy = [...this.rowKey]
    this.checkList = this.rowKey.map((item) => item.key)
  },
  methods: {
    rowCheckChange(e) {
      let rowKey = this.rowKeyCopy.filter((item) => e.includes(item.key))
      this.$emit('rowCheckChange', e, rowKey)
    }
  }
}
</script>

<style lang="scss" scoped>
.check_max {
  min-width: 150px;
  padding: 12px;
}
</style>
